-- @owner: @kyeleze
-- @date: 2022/5/13
-- @testpoint: assignment模式下,自定义函数中返回值的类型与cast的target_type类型不一致但能二进制强转; 创建成功

--step1:建立自定义类型转换函数;expect:创建函数成功
create or replace function timezone_to_secondsinteger
(
    in time with time zone
)
returns varchar
as
$$
declare
seconds varchar;
begin
select (
extract(hour from $1)::integer * 3600
+ extract(minute from $1)::integer * 60
+ extract(seconds from $1)::integer* 1)::varchar into seconds;
return seconds;
end;
$$ language plpgsql;
/

--step2:创建assignment模式转换关系;expect:创建成功
drop cast if exists (time with time zone as varchar) cascade;
create cast(time with time zone as varchar) with function timezone_to_secondsinteger(time with time zone) as assignment;

--step3:清理环境;expect:清理成功
drop cast if exists (time with time zone as varchar) cascade;
drop function if exists timezone_to_secondsinteger(time with time zone) cascade;
